<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="">
              <a-input placeholder="请输入品类名称" v-model="queryParam.queryName"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="">
              <a-input placeholder="请输入品类编号" v-model="queryParam.queryCode"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" style="color: #F9D532;width: 80px;height: 36px;background: #333333;border-style: none;">查询</a-button>
              <a-button type="primary" @click="searchReset" style="margin-left: 8px;width: 80px;height: 36px;background: #eae7e7;border-style: none;color: #323232">重置</a-button>
            </span>
          </a-col>

          <a-button type="primary" @click="add_category(0)" icon="plus" style="color: #F9D532;width: 110px;height: 36px;background: #333333;border-style: none;float: right;margin-right: 16px;" v-show="this.tabs==2">新增品类</a-button>
        </a-row>
      </a-form>
    </div>


    <div style="background: #f2f2f2;height: 10px;width: auto;margin-top: 10px;margin-bottom: 30px;"></div>


    <div>
      <div style="border: none;background-color: #ffffff;padding-bottom: 28px;">
<!--        <span style="font-size: 16px;float: left;color:#000000;font-weight: bold">品类列表</span>-->
        <a-tabs @change="bubu" style="margin-top: -20px">
          <a-tab-pane tab="启用中品类" key="1"></a-tab-pane>
          <a-tab-pane tab="品类草稿件" key="2"></a-tab-pane>
        </a-tabs>
<!--        <a-button type="primary" style="background-color:#f2f2f2;color: #565656; border-style: none;float: right;margin-right: 10px;" icon="download" @click="handleExportXls('劳务公司列表')">导出</a-button>-->
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange" v-show="this.tabs==1" style="margin-top: -20px;">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.img)" icon="img"/>
          </div>
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <div align="center" style="align-content: center;margin-left: 30px;">
          <a @click="see_companyDetail(record.id)" style="float: left;margin-left: 10px;font-size: 14px;color: #d29328;">查看详情</a>
          <a @click="see_companyDetail(record.id)" style="float: left;margin-left: 10px;font-size: 14px;color: #d29328;">进入草稿件</a>
          </div>
        </span>
      </a-table>


      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns2"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange" v-show="this.tabs==2" style="margin-top: -20px;">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.img)" icon="img"/>
          </div>
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <div align="center" style="align-content: center;margin-left: 30px;">
          <a @click="goto_setcategory_home(record.id)" style="float: left;margin-left: 10px;font-size: 14px;color: #d29328;">配置</a>
          <a @click="add_category(record)" style="float: left;margin-left: 10px;font-size: 14px;color: #d29328;">编辑</a>
          <a-menu-item style="float: left;margin-left: 10px;">
             <a-popconfirm title="确定删除该品类吗?" @confirm="() => handleEdit_staus(3,record.id)">
                  <a style="font-size: 14px;color: #d29328;" v-show="record.guaStaus!=3">删除</a>
                </a-popconfirm>
          </a-menu-item>
          </div>
        </span>
      </a-table>
    </div>

    <AddCategoryModule ref="modalForm" @ok="modalFormOk"></AddCategoryModule>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {putAction,getFileAccessHttpUrl} from '@/api/manage';
  import JDate from '@/components/jeecg/JDate.vue'
  import '@/assets/less/TableExpand.less'
  import AddCategoryModule from './modules/AddCategoryModule'

  export default {
    name: "categoryinfo",
    mixins:[JeecgListMixin],
    components: {
      JDate,
      AddCategoryModule
    },
    data () {
      return {
        description: 'categoryinfo管理页面',
        tabs: 1,//切换框
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'品类名称',
            align:"center",
            dataIndex: 'categoryName'
          },
          {
            title:'性别',
            align:"center",
            dataIndex: 'categorySex',
            customRender:function (text) {
               if(text=='0'){
                 return "全部"
               }else if(text=='1'){
                 return "男装"
               }else if(text=='2'){
                 return "女装"
               }
            }
          },
          {
            title: '图片',
            align: "center",
            width: 150,
            dataIndex: 'img',
            scopedSlots: {customRender: "avatarslot"}
          },
          {
            title:'品类编号',
            align:"center",
            dataIndex: 'categoryCode'
          },
          {
            title:'品类说明',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],

        columns2: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'品类名称',
            align:"center",
            dataIndex: 'categoryName'
          },
          {
            title:'性别',
            align:"center",
            dataIndex: 'categorySex',
            customRender:function (text) {
              if(text=='0'){
                return "全部"
              }else if(text=='1'){
                return "男装"
              }else if(text=='2'){
                return "女装"
              }
            }
          },
          {
            title: '图片',
            align: "center",
            width: 150,
            dataIndex: 'img',
            scopedSlots: {customRender: "avatarslot"}
          },
          {
            title:'品类编号',
            align:"center",
            dataIndex: 'categoryCode'
          },
          {
            title:'品类说明',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/admin/parameter/categoryinfoList",
          delete: "/companymanger/lgyxCompanymanger/delete",
          edit_staus: "/companymanger/lgyxCompanymanger/edit_staus",
          deleteBatch: "/companymanger/lgyxCompanymanger/deleteBatch",
          exportXlsUrl: "/LaborEnterprise/download2",
          importExcelUrl: "companymanger/lgyxCompanymanger/importExcel"
        }
      }
    },
    methods: {
      bubu (e) {
        this.total = 0
        this.tabs = e
        this.ipagination.current=1;
        if (e == 1) {
          this.url.list = '/admin/parameter/categoryinfoList'
        }else {
          // alert(e);
          this.url.list = '/admin/parameter/test_categoryinfoList'
        }
        this.loadData();
      },
      getAvatarView: function (avatar) {
        return getFileAccessHttpUrl(avatar)
      },
      add_category(record) {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = "新增/编辑品类";
        this.$refs.modalForm.disableSubmit = true;
      },
      goto_setcategory_home(categoryid){
        // alert(categoryid)
        // 1.  不带参数
        // this.$router.push('/home')
        // this.$router.push({name:'home'})
        // this.$router.push({path:'/home'}
        // 2. query传参
        // this.$router.push({name:'home',query: {id:'1'}})
        // this.$router.push({path:'/home',query: {id:'1'}})
        // html 取参  $route.query.id
        // script 取参  this.$route.query.id
        this.$router.push({path:'/setcategory/chanshu',query: {id:categoryid}})
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>